package system.security.entity;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

@Entity
@Table(name="se_user")
@PrimaryKeyJoinColumn(name="id")
public class User extends Resource {
	
	private String username;
	private String passpord;
	
	protected Set<Authority> authorities = new HashSet<Authority>();
	
	public User(){
		super();
		resourceType = new ResourceType("User");
	}
	
	@Column
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column
	public String getPasspord() {
		return passpord;
	}

	public void setPasspord(String passpord) {
		this.passpord = passpord;
	}

	@ManyToMany(cascade = {CascadeType.PERSIST}, fetch=FetchType.LAZY)
	@JoinTable(name = "se_user_authority", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "authority_id") })
	public Set<Authority> getAuthorities() {
		return authorities;
	}

	public void setAuthorities(Set<Authority> authorities) {
		this.authorities = authorities;
	}
	
	

}
